﻿using System;
using System.Collections.Generic;
using System.Text;

namespace System;

public static class DateTimeExtensions
{
    public static DateTime ChangeKind(this DateTime dateTime, DateTimeKind kind)
    {
        if (dateTime.Kind == kind)
        {
            return dateTime;
        }
        else if (dateTime.Kind == DateTimeKind.Unspecified || kind == DateTimeKind.Unspecified)
        {
            return new DateTime(dateTime.Ticks, kind);
        }
        else if (kind == DateTimeKind.Utc)
        {
            return dateTime.ToUniversalTime();
        }
        else
        {
            return dateTime.ToLocalTime();
        }
    }

    public static DateTime AsKind(this DateTime dateTime, DateTimeKind kind)
    {
        return dateTime.Kind == kind ? dateTime : new DateTime(dateTime.Ticks, kind);
    }
}
